package com.interview.elasticjob.job;

import com.config.autofig.ElasticSimpleJob;
import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import com.interview.elasticjob.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @Function: 注意分片数
 * @Author: aqie
 * @Date: 2019/8/5 19:54
 */
@Slf4j
@ElasticSimpleJob(
        jobName = "mySimpleJob" ,
        cron = "0/5 * * * * ?",
        shardingTotalCount = 1,
        overwrite = true
)
public class MySimpleJob implements SimpleJob {
    @Autowired
    private OrderService orderService;

    @Override
    public void execute(ShardingContext shardingContext) {
        log.info("我是mySimpleJob分片 " + shardingContext.getShardingItem() +
                "总分片项" + shardingContext.getShardingTotalCount());
        // 模拟创建订单
        for (int i=0;i<10;i++){
            orderService.insertOrder();
        }
    }
}
